<template>
  <h1>注册页面</h1>
  <el-card style="width: 450px;margin: 0 auto;padding:20px 10px 0 0 " >
    <el-form  label-width="60px">
      <el-form-item label="用户名:">
        <el-input placeholder="请输入用户名" v-model="register.username"></el-input>
      </el-form-item>
      <el-form-item label="密码:">
        <el-input placeholder="请输入密码" v-model="register.password"></el-input>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input placeholder="请输入昵称" v-model="register.nickname"></el-input>

      </el-form-item>
      <el-form-item>
     <el-button type="primary" style="width: 100%;" @click="reg()">注册</el-button>
      </el-form-item>

    </el-form>
  </el-card>
</template>

<script setup>
import {ref} from "vue";
import axios from "axios";
import{ElMessage} from "element-plus";
import router from "@/router";
import qs from "qs";

const register=ref({
  username:'',
  password:'',
  nickname:''
})

const reg=()=>{
  console.log(register.value);
  let data=qs.stringify(register.value);
  console.log(data);
  //前端通过这个方法发送数据给后端
  axios.post('http://localhost:8080/v1/users/reg',data)
       .then((response)=>{
         console.log(response.data)
         if (response.data.code==2002)
         ElMessage.success('注册成功')
         //跳转页面,需要导包
         router.push('/');
           })
}
</script>

<style scoped>

</style>